Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Count sigops on electrs side #43

Merged
merged 2 commits into from
Sep 18, 2023
Merged

Feature: Count sigops on electrs side #43

merged 2 commits into from
Sep 18, 2023

Conversation

junderw
Copy link
Member

@junderw junderw commented Sep 15, 2023

Closes #42

Currently it only returns the sigops count. This new sigops value will be returned by the REST for all endpoints, both chain and mempool.

Is that enough, or should we also calculate the adjusted VSize and whatnot?

I'm sure it doesn't matter either way, feel free to add whatever you want to the TransactionValue struct.

@junderw
Copy link
Member Author

junderw commented Sep 15, 2023

Adding a bunch of errors where "Couldn't count sigops" might bubble up is a bit scary, but if you look at each error, it would require the transaction to be invalid in order to hit any of these.

Also, the prevouts not being the same length and missing prevouts etc. would be caught by the function before it.

src/util/transaction.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@mononaut mononaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested ACK @ 4a76234a

Code looks good to me. I agree that the structure is a little odd, but it makes it easy to compare with Core's implementation and confirm that the same logic is reproduced.

There was no measurable performance impact, even on the heavy bulk transaction endpoints.

I cross-tested against the nodejs implementation, and confirmed that the sigop counts were consistent for the ~500k transactions currently in my mempool (except for certain transactions with P2SH multisig inputs, where the error is on the nodejs side 😅).

src/util/transaction.rs Show resolved Hide resolved
Copy link
Contributor

@mononaut mononaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(reverting my earlier ACK)
Tested NACK @ 4a76234a

It turns out that this actually chokes on coinbase transactions.

src/util/transaction.rs Outdated Show resolved Hide resolved
@junderw junderw force-pushed the junderw/sigops branch 2 times, most recently from 87da5d8 to a03b4f4 Compare September 16, 2023 23:38
@junderw
Copy link
Member Author

junderw commented Sep 17, 2023

Note: Here are examples of ScriptSigs that fail due to being invalid (But Core still manages to count their sigops.) (From @mononaut)

d8828d17a7bdcff5733d7c9c31d8d3bb08bd1ac41e0711d4bf6d47d7542b47cb
works fine
f1220af34ed325cbe56fd76527acfb830b38c8a7edfe524165de16098a8d0f44
fails

Seems like the sigop counting pipeline doesn't care if you have a PUSHDATA_47 without 47 bytes to push, it'll just return the sigops.

@junderw
Copy link
Member Author

junderw commented Sep 17, 2023

Fixed.

@junderw
Copy link
Member Author

junderw commented Sep 17, 2023

I noticed the recent change removed the need for Result in one of the functions... it propagated outward and changed a bunch of the function signatures.

Copy link
Contributor

@mononaut mononaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested reACK @ 310b428

confirmed it handles coinbases that can't be parsed as valid scriptsigs now.

Copy link
Member

@softsimon softsimon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested ACK @ [881ca56]

@softsimon softsimon merged commit 3b16c0a into mempool Sep 18, 2023
7 checks passed
@softsimon softsimon deleted the junderw/sigops branch September 18, 2023 17:53
SatoKentaNayoro pushed a commit to boolnetwork/mempool-electrs that referenced this pull request Nov 29, 2024
Feature: Count sigops on electrs side
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for Sig Op calculation and adjusted sizes
3 participants